package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.nearshop.net.entity.Comment;

public class GetMerchantCommentListResponse {

    public NetStatus status = null;
    
    public String total = null;

    public List<Comment> comments = null;

    public GetMerchantCommentListResponse() {
        comments = new ArrayList<Comment>();
    }

    public void parseJson(String response) {
//        System.out.println(response);
        try {
            JSONObject jsonObject = new JSONObject(response);
            total = jsonObject.optString("total");
            status = NetStatus.getStatus(jsonObject.optString("status"));

            if(!jsonObject.isNull("commentList")){
                JSONArray commentArray = jsonObject.optJSONArray("commentList");
                for (int a = 0; a < commentArray.length(); a++) {
                    Comment comment = new Comment();
                    comment.parseEntity(commentArray.getJSONObject(a));
                    comments.add(comment);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
